<?php

/*

Upgrading Shop (upgrade_shop.pro.php)

*/
ob_start();
include "global.inc.php";

$find_shop = fetch("SELECT * FROM usershops2 WHERE owner = '$userid' AND game = '$game'");

if (!$find_shop[id])
{
	die("You do not have a shop yet, please click <a href=makeshop.php?game=$game>here</a> to create one.$closeHTML");
}

$max_stock = $find_shop[shop_size] * 5;
$cost_2_upgrade = ($find_shop[shop_size] * 50) + 50;
$next_level = $find_shop[shop_size] + 1;

if ($use_token == "true")
{
	$findTokens = fetch("SELECT * FROM upgrade_tokens WHERE user = '$userid' AND game = '$game' AND upgrade = 'shop'");
	if ($findTokens[ammount] <= 0)
	{
		die(header(error("upgrade_shop.php?game=$game","You do not have any Upgrade Shop Tokens!")));
	}

	mysql_query("UPDATE upgrade_tokens SET ammount=$findTokens[ammount]-1 WHERE user = '$userid' AND game = '$game' AND upgrade = 'shop'");

	mysql_query("UPDATE usershops2 SET shop_size=$find_shop[shop_size]+1 WHERE owner = '$userid' AND game = '$game'");

	die(header(error("upgrade_shop.php?game=$game","You used a token and your shop has been upgraded!")));
}

if ($use_token != "true")
{
	if ($next_upgrade != $next_level)
	{
		die(header(error("upgrade_shop.php?game=$game","An error occured while processing 	this page, please be sure to only click the upgrade button once!")));
	}

	if ($points < $cost_2_upgrade)
	{
		die(header(error("upgrade_shop.php?game=$game","You cannot afford to upgrade your 	shop right now.")));
	}
	mysql_query("UPDATE usershops2 SET shop_size=$find_shop[shop_size]+1 WHERE owner = '$userid' AND game = '$game'");

	points($game,"$username", "-$cost_2_upgrade");
}

die(header(error("upgrade_shop.php?game=$game","Your shop has been upgraded!")));

?>